#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int minn=1e9+10;
int a[N]={0},b[N]={0},c[N]={0},d[N]={0};
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n-1;i++) b[i]=fabs(a[i+1]-a[i]);
	for(int i=1;i<=n-1;i++) c[i]=c[i-1]+b[i];
	for(int i=1;i<=n-m+1;i++)
	{
		int ans=fabs(c[i+m-2]-c[i-1]);
		minn=min(minn,ans);
	}
	cout<<minn;
	return 0;
}
